home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / chasm01.sha / chasm.doc < prev    next >
Text File  |  1995-03-23  |  11KB  |  430 lines

  1.  
  2.                 C H A S M
  3.  
  4.              Chip 48 v2.25 assembler
  5.  
  6.          Written by Steve Scherf, steve@Altos.COM
  7.  
  8.              Copyright (c) 1991 Steve Scherf
  9.  
  10.  
  11. This documentation and the accompanying source code may be freely distributed
  12. with the following restrictions:
  13.  
  14.     - All files must be distributed intact and unaltered. Any fixes or
  15.       patches to any of the files must be distributed as separate
  16.       information, but may be included with the original files.
  17.  
  18.     - No person other than the author may sell this software or
  19.       distribute it with any product which is not in the public domain
  20.       or is intended for sale.
  21.  
  22.     - This software is provided as-is, and is not promised to perform
  23.       reliably. The user of this software does so at his own risk.
  24.  
  25.     - Possession of this software implies knowledge and acceptance of
  26.       these copyright restrictions.
  27.  
  28.  
  29. The following is the list of files that are included in this distribution:
  30.  
  31.     chasm.c
  32.     chasm.doc
  33.     chasm.h
  34.     grammar.y
  35.     lex.c
  36.     link.c
  37.     Makefile
  38.     README
  39.     sample.ch
  40.  
  41.  
  42. Chasm v0.1
  43.  
  44. The purpose of this program is to aid in the creation of programs for
  45. the Chip 48 v2.25 virtual machine, written by Andreas Gustafsson
  46. (gson@niksula.hut.fi). This document assumes a fundamental understanding of
  47. Chip 48. For a description of the Chip 48 program, please refer to the
  48. documentation which is available from a variety of ftp sites and mail servers.
  49.  
  50.  
  51. HOW TO USE "CHASM":
  52.  
  53. Usage:    chasm [-a] [-o output_file] input_file
  54.  
  55. The "input_file" must be a text file consisting of legal "chasm" instructions.
  56. The instructions in this file will be converted to a binary suitable for
  57. execution by the Chip 48 v2.25 virtual machine. The "-a" option causes output
  58. to be in the form of ascii hex characters rather than in an executable binary
  59. format. This is useful for debugging, as it provides a human-readable output
  60. file. The "-o" option forces the output to be placed in the filename specified
  61. by "output_file". If an error occurs during assembly, no output file is
  62. generated.
  63.  
  64. Files created by "chasm" are:
  65.  
  66.     c.out - The default name of the executable binary produced by "chasm".
  67.     c.ascii - The default name of the ascii hex file produced by "chasm".
  68.     c.tmp - A temporary file used during assembly.
  69.  
  70.  
  71. INSTRUCTION DESCRIPTIONS:
  72.  
  73. The following text describes the usage and syntax of the "chasm" instruction
  74. set. The descriptions are all in the following format:
  75.  
  76. MNEMONIC:    what the mnemonic stands for
  77.  
  78.     syntax rules
  79.  
  80.     Explanation of the instruction.
  81.  
  82. In the syntax rules:
  83.  
  84. "constant" is a value represented by a number, a single-quoted character, or
  85.     a label. Numbers may be hex, decimal or octal. These types are
  86.     specified as they are in the C language; i.e. hex numbers are
  87.     preceded by 0x, octal numbers are preceded by a zero and decimal
  88.     numbers have no preceding characters. Single-quoted characters
  89.     represent the ascii value of that character. Special characters may
  90.     be escaped as in C.
  91.  
  92.     Examples:
  93.  
  94.         0xA9    - hex A9 or decimal 169
  95.         075    - octal 75 or decimal 61
  96.         32    - decimal 32
  97.         'c'    - decimal 99
  98.  
  99.     Special escape characters are:
  100.  
  101.         '\t'    - tab or decimal
  102.         '\b'    - backspace or decimal
  103.         '\r'    - carriage return or decimal
  104.         '\n'    - newline or decimal
  105.         '\0'    - null or decimal 0
  106.         '\\'    - backslash or decimal
  107.  
  108.     Any escaped character that is not in the above list is treated as if
  109.     it were not escaped.
  110.  
  111.     A special form of constant is a string. As in many languages, a string
  112.     is a series of characters preceded and ended by double quotes. The
  113.     special escape characters defined above are also valid within strings.
  114.     Strings may only be used in the data instruction and have the same
  115.     effect as a series of constants.
  116.  
  117.     Example:
  118.  
  119.         "abcd"
  120.  
  121.         is the same as
  122.  
  123.         'a', 'b', 'c', 'd'
  124.  
  125.         or
  126.  
  127.         97, 98, 99, 100
  128.  
  129. "label" is a word not beginning with a digit and composed of alphanumeric
  130.     characters and/or the underbar ("_") character.
  131.  
  132. "register" is a "V" followed by a single hex digit. This corresponds to one
  133.     of the 16 virtual machine registers.
  134.  
  135. "dtimer", "stimer", and "I" correspond to the special predefined variables
  136.     delay_timer, sound_timer, and I respectively. For explanations of
  137.     these variables, see the documentation for Chip 48 v2.25.
  138.  
  139.  
  140. In the explanation of the instructions, "arg1", "arg2" and "arg3" refer to the
  141. first, second and third arguments to the instruction respectively.
  142.  
  143. Instructions that are marked with an asterisk are pseudo-instructions.
  144.  
  145. ADD:    add
  146.  
  147.     add constant, register
  148.     add register, register
  149.     add register, I
  150.  
  151.     Add arg1 and arg2 and put the result in arg2. In the second case
  152.     VF is true if a carry occurred.
  153.  
  154. AND:    and
  155.  
  156.     and register, register
  157.  
  158.     Store the bitwise and of arg1 and arg2 in arg2.  VF may change.
  159.  
  160. BCD:    binary coded decimal
  161.  
  162.     bcd register
  163.  
  164.     Store the three byte binary coded decimal representation of arg1 in
  165.     the memory address pointed to by I. (I ... I+2)
  166.  
  167. CLD:    clear display
  168.  
  169.     cld
  170.  
  171.     Clear the display.
  172.  
  173. DATA: *    data
  174.  
  175.     data datalist
  176.  
  177.     Store a list of one-byte constants in memory, where datalist is a
  178.     list of constants and/or strings separated by commas. Examples:
  179.  
  180.         data 'a', 'b', 'c'
  181.         data 0xAB, "hello", 56, 0123, xyz
  182.  
  183.     In the latter example, xyz is a label that must be defined somewhere
  184.     within the program. The data list may span more than one line.
  185.  
  186. DEF: *    define
  187.  
  188.     def label, constant
  189.  
  190.     Assign a value to a label. Example:
  191.  
  192.         def xyz, 0xFF
  193.  
  194. DMP:    dump
  195.  
  196.     dmp register
  197.  
  198.     Dump registers V0 through arg1 to the memory address pointed to by I.
  199.  
  200. DSP:    display sprite
  201.  
  202.     dsp constant, register, register
  203.  
  204.     Display sprite pointed to by I. The sprite is taken to be arg1 bytes
  205.     long and is displayed at coordinates arg2, arg3. VF is true if a
  206.     collision occurred with another sprite.
  207.  
  208. INK:    input key
  209.  
  210.     ink register
  211.  
  212.     Get keypress and store hex value in arg1. Execution is suspended
  213.     until a key is pressed. The speaker beeps when a key is pressed.
  214.  
  215. JMP:    jump
  216.  
  217.     jmp constant
  218.  
  219.     Cause execution to branch to the instruction at address arg1.
  220.  
  221. JOF:    jump to offset
  222.  
  223.     jof constant
  224.  
  225.     Cause execution to branch to the instruction at address arg1 plus
  226.     the value in V0. This is good for branch tables. Offsets are easy
  227.     to compute since all true instructions are two bytes; pseudo-
  228.     instructions are as follows: "mem" takes exactly as many bytes as
  229.     specified; "data" takes one byte per element in the data list, and
  230.     one byte per character in a string; "def" takes no memory. Keep in
  231.     mind that if an odd number of bytes is specified with "mem" or "data",
  232.     a pad byte may be added before the next instruction to insure that
  233.     it is on an even address boundary.
  234.  
  235. JSR:    jump to subroutine
  236.  
  237.     jsr constant
  238.  
  239.     Cause execution to branch to the instruction at address arg1. Execution
  240.     returns to the branch point when a "ret" instruction is executed.
  241.  
  242. MEM: *    memory
  243.  
  244.     mem constant
  245.  
  246.     Allocate arg1 bytes of memory. Memory is all zeros.
  247.  
  248. MOV:    move
  249.  
  250.     mov register, register
  251.     mov constant, register
  252.     mov constant, I
  253.     mov register, {stimer, dtimer, I}
  254.     mov dtimer, register
  255.  
  256.     Store value of arg1 in arg2. In the first case VF may change.
  257.  
  258. OR:    or
  259.  
  260.     or register, register
  261.  
  262.     Store the bitwise or of arg1 and arg2 in arg2.  VF may change.
  263.  
  264. RES:    restore
  265.  
  266.     res register
  267.  
  268.     Restore registers V0 through arg1 from the memory address pointed to
  269.     by I.
  270.  
  271. RET:    return
  272.  
  273.     ret
  274.  
  275.     Cause execution to branch to the instruction following the last
  276.     "jsr" instruction executed.
  277.  
  278. RND:    random
  279.  
  280.     rnd constant, register
  281.  
  282.     Generate a random number bitwise and arg1. The result is stored
  283.     in arg2.
  284.  
  285. SAR:    subtract and replace
  286.  
  287.     sar register, register
  288.  
  289.     Subtract arg2 from arg1 and put the result in arg2; VF equals
  290.     not borrow.
  291.  
  292.  
  293. SEQ:    skip if equal
  294.  
  295.     seq register, register
  296.  
  297.     Skip the next instruction if arg1 equals arg2.
  298.  
  299. SHL:    shift left
  300.     
  301.     shl register
  302.  
  303.     Shift arg1 left one bit; VF equals carry.
  304.  
  305. SHR:    shift right
  306.  
  307.     shr register
  308.  
  309.     Shift arg1 right one bit; VF equals carry.
  310.  
  311. SIP:    skip if pressed
  312.  
  313.     sip register
  314.  
  315.     Skip the next instruction if the key represented by the hex value
  316.     arg1 is pressed.
  317.  
  318. SNE:    skip if not equal
  319.  
  320.     sne constant, register
  321.     sne register, register
  322.  
  323.     Skip the next instruction if arg1 does not equal arg2.
  324.  
  325. SNP:    skip if not pressed
  326.  
  327.     snp register
  328.  
  329.     Skip the next instruction if the key represented by the hex value
  330.     arg1 is not pressed.
  331.  
  332. SSC:    set sprite coordinates
  333.  
  334.     ssc register
  335.  
  336.     Store the address of a 5 byte font sprite for the hex character
  337.     arg1.
  338.  
  339. SUB:    subtract
  340.  
  341.     sub register, register
  342.  
  343.     Subtract arg1 from arg2 and put the result in arg2; VF equals
  344.     not borrow.
  345.  
  346. XOR:    exclusive or
  347.  
  348.     xor register, register
  349.  
  350.     Store the bitwise exclusive or of arg1 and arg2 in arg2. VF may change.
  351.  
  352.  
  353. NOTES:
  354.  
  355. 1]    Labels may be used before they are defined, as long as they are defined
  356.     somewhere within the file. The only exception is the "mem"
  357.     pseudo-instruction; labels used in this instruction must be defined
  358.     in advance.
  359.  
  360. 2]    In addition to the "def" instruction, a label may be defined by
  361.     putting it on a line by itself followed by a colon. This will
  362.     set the value of the label to the address of the instruction following
  363.     the label definition.
  364.  
  365.     Example:
  366.  
  367.         add V0, V1
  368.         xyz:
  369.         mov 0xFF, V3
  370.  
  371.     In this code fragment, xyz is set to the address of the "mov"
  372.     instruction. This label is suitable for use in a "jmp", "jsr" or
  373.     "jof" instruction.
  374.  
  375. 3]    The maximum size for a constant is 0xFFF. Some instructions require
  376.     a constant to be smaller. The general rule is: addresses must be
  377.     <= 0xFFF, numerical constants must be <= 0xFF, and sprite sizes
  378.     must be <= 0xF. Using a value that is too large will generate an
  379.     assembler error.
  380.  
  381. 4]    Since both data and instructions share common space, care must be
  382.     taken to ensure that program execution does not fall into addresses
  383.     containing data. This will result in program failure unless the data
  384.     resembles legal instructions. Data space is allocated with the "data"
  385.     and "mem" pseudo-instructions.
  386.  
  387. 5]    Instructions must occupy a single line, except for the "data"
  388.     instruction.
  389.  
  390. 6]    Blank lines and white space are ignored.
  391.  
  392. 7]    Instructions, registers, and numerical constants may be specified in
  393.     either upper or lower case.
  394.  
  395. 8]    Comments are delineated by either the ";" or the "/" character.
  396.     Any text after either of these two characters is ignored by the
  397.     assembler until a newline is reached, so comments must appear after
  398.     instructions.
  399.  
  400.  
  401. ERROR MESSAGES:
  402.  
  403. Error messages generated by the assembler are accompanied by an input file
  404. line number indicating which line in the input file had the error.
  405. Below is a list of possible assembler error messages and their meanings.
  406.  
  407. "label multiply defined" - A label has been defined more than once.
  408.     
  409. "constant must be forward declared" - A previously undefined label has been
  410.     used in a "mem" instruction.
  411.  
  412. "illegal variable usage" - A special variable has been used as an argument
  413.     to an instruction that does not allow that variable.
  414.  
  415. "duplicate label" - More than one "line label" in a row has been defined.
  416.  
  417. "constant out of range" - A constant on the specified line is larger than 0xFFF.
  418.  
  419. "Error - program too large for address space" - The binary that would be
  420.     generated from the input file is larger than the maximum legal size.
  421.     The maximum addressible memory location is 0xFFF, but the first 0x200
  422.     bytes of address space are reserved. Thus, the maximum binary size is
  423.     0xDFF bytes.
  424.  
  425. "Error - undefined labels:" - The list of labels following this message have
  426.     not been defined.
  427.  
  428. "Error - constant size:" - The list of line numbers following this message
  429.     specifies instructions that have constants that are illegally large.
  430.